<?php
require("conn.php");
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$sid = $_POST["sid"];
$published = $_POST["published"];
$image =  $_POST["image"];
$tag = $_POST["tag"];
$slcmenu = $_POST["slcmenu"];
$vi_title=$_POST["vi_title"];
$vi_summary=$_POST["vi_summary"];
$vi_content=$_POST["vi_content"];
$vi_content = str_replace("href=", "<a onclick=window.open(", $vi_content);
$en_title=$_POST["en_title"];
$en_summary= $_POST["en_summary"];
$en_content=$_POST["en_content"];
$en_content = str_replace("href=", "onclick=window.open(", $en_content);
$art_order = $_POST["art_order"];
$created_date= 'NOW()';
$user_id = $_SESSION["UserID"];
$featured = $_POST["featured"];
$newshot = $_POST["newshot"];
$sql=sprintf("insert into tblarticle (section_id,published,image,tag,vi_title,vi_summary,vi_content,en_title,en_summary,en_content, art_order, created_date,user_id,featured,menuid)   values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',NOW(),'%s','%s','%s')",
	$sid,$published,$image, $tag,$vi_title,$vi_summary,$vi_content,$en_title,$en_summary,$en_content,$art_order ,$user_id,$featured,$newshot,$slcmenu);

$rs=mysql_query($sql) or die(mysql_error());
			 
if(!$rs)
{
	
?>
	<script language="javascript">
		alert("Thêm bài viết không thành công");
		
	</script>
<?php
}
else
{
	
	
	
	
?>
	<script language="javascript">
		alert("Thêm bài viết thành công");
		window.location="article";
	</script>
<?php
}

?>